<?php
class AML_View_Helper_TopMenu extends Zend_Controller_Action_Helper_Abstract
{
    public function topmenu ()
    {
        //$curr_lang = $sess->current_lang;
        $registry = Zend_Registry::getInstance();
        $this->db = $registry->get('db');
	    $view = new Zend_View();
	    $view->addHelperPath('../library/View/Helper','Lion_View_Helper');
        $parent_item_arr = $this->db->fetchAll("
			SELECT menu_id, title, parent_id, has_child
			FROM menu
			WHERE parent_id = 0 AND status = 1
		");
?>
		<div id="t-menu">
			<div id="smoothmenu1" class="ddsmoothmenu">
				<ul>
<?php
	    foreach ($parent_item_arr as $parent_items) 
	    {
?>			
				<?php
					if($parent_items['has_child'] == 0) { 
				?>
					<li class="1st-mnu"><a href=""><?php echo $view->translate("%" . $parent_items['title']); ?></a></li>
				<?php } else { ?>
				<li>
				<a href=""><?php echo $view->translate("%" . $parent_items['title']); ?></a>
					<ul>
						<?php
							foreach ($this->getChildItems($parent_items['menu_id']) as $child_items) {
						?>
								<li><a href="<?php echo $child_items['url']; ?>"><?php echo $view->translate("%" . $child_items['title']); ?></a></li>
						<?php
							}
						?>
					</ul>		
<?php
	    }
?>
					</li>
					<?php } ?>
				</ul>
			</div>	
		</div>
<?php
	    
    }
    
    private function getChildItems($parent_id)
    {
    	$child_item_arr = $this->db->fetchAll("
    		SELECT menu_id, title, url
    		FROM menu
    		WHERE parent_id = '" . $parent_id . "' AND status = 1
    	");
    	
    	return $child_item_arr;
    }
}
